package org.minuframework.time;

import java.util.Date;

public class DateTime {

    private Date date;

    public DateTime() {
        this.date = new Date();
    }

    public DateTime(long date) {
        this.date = new Date(date);
    }

    public DateTime(Date date) {
        this.date = date;
    }

    public DateTime(String date) {
        this.date = TimeUtils.dateTimeFormat(date);
    }

    public DateTime(String date, String format) {
        this.date = TimeUtils.formatDateTime(date, format);
    }

    public void add(long times) {
        long time = date.getTime();
        long result = time + times;
        this.date = new Date(result);
    }

    public void addYears(int years) {
        this.date = TimeUtils.offsetDateYear(this.date, years);
    }

    public void addMonths(int months) {
        this.date = TimeUtils.offsetDateMonth(this.date, months);
    }

    public void addWeeks(int weeks) {
        this.date = TimeUtils.offsetDateWeek(this.date, weeks);
    }

    public void addDays(int days) {
        this.date = TimeUtils.offsetDateDay(this.date, days);
    }

    public void addHours(int hours) {
        this.date = TimeUtils.offsetDateHour(this.date, hours);
    }

    public void addMinutes(int minutes) {
        this.date = TimeUtils.offsetDateMinute(this.date, minutes);
    }

    public void addSeconds(int seconds) {
        this.date = TimeUtils.offsetDateSecond(this.date, seconds);
    }

    public Date getDate() {
        return date;
    }

    @Override
    public String toString() {
        return TimeUtils.dateTimeFormat(this.date);
    }

    public String toString(String format) {
        return TimeUtils.formatDateTime(this.date, format);
    }

}
